<template>
	<view>
		<view class="renwu-list">
			<view class="renwu-item" v-for="(vo,index) in list" :key="index">
				<view class="renwu-title">{{ vo.name }}</view>
				<view class="renwu-time">
					<text class="lable">领取时间：</text>
					<text class="content">{{vo.start_on && vo.start_on.substr(0, 10)}} 至 {{vo.end_on && vo.end_on.substr(0, 10)}}</text>
				</view>
				<view class="renwu-time">
					<text class="lable">可领取任务等级：</text>
					<text class="content">
						<text style="display: inline-block;padding-right: 20rpx;" v-for="(voo,idx) in vo.task_levels_text">{{ voo.name }} </text>
					</text>
				</view>
				<view class="renwu-time">
					<text class="lable">奖励周期：</text>
					<text class="content">任务完成后{{ vo.reward_duration }}天</text>
				</view>
				<view class="renwu-footer">
					<view class="btn-renwu-b" @tap="taskDetail(vo)">查看详情</view>
					<view class="btn-renwu-a" @tap="receiveTask(vo)">立即参与</view>
				</view>
			</view>
		</view>
				
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params:{
					page: 1,
					per_page: 10,					
				},
				isEmpty: false,
				loadStatus: 'loadmore',
				lastPage: 1,
				total: 0,
				list: [],
			}
		},
		onReachBottom() {
			if (this.params.page < this.lastPage) {
				this.params.page += 1;
				this.init();
			}
		},
		created() {
			this.init();
		},
		methods: {
			init(){
				let that = this;
				uni.showLoading({title: '加载中'});
				that.$http('task.list', this.params).then(res => {
					uni.hideLoading();
					if (res.code == 1) {
						that.list = [...that.list, ...res.data.data];
						that.isEmpty = !that.list.length;
						that.lastPage = res.data.last_page;
						that.loadStatus = that.currentPage < that.lastPage ? 'loadmore' : 'nomore';
					} else {
						that.showEmpty = true;
					}
				});
			},
			loadMore() {
				if (this.loadStatus !== 'nomore') {
					this.params.page += 1;
					this.init();
				}
			},
			taskDetail(vo) {
				this.$Router.push({ path: '/pages/app/renwu/detail', query: { id: vo.id } });
			},
			receiveTask(vo) {
				let that = this;
				uni.showLoading({title: '加载中'});
				that.$http('task.receiveTask', {task_id: vo.id}).then(res => {
					uni.hideLoading();
					this.$u.toast(res.msg);
					if (res.code == 1) {
						
					}
				});
			}
		}
	}
</script>

<style lang="less">
	pages {
		background: #f1f1f1;
	}

	.renwu-item {
		margin: 20rpx;
		padding: 20rpx;
		background: #fff;
		border-radius: 10rpx;
		
		.renwu-title{
			font-size:32rpx;
			font-weight:bold;
			line-height:160%;	
			padding-bottom:10rpx;
			}
		.renwu-time{
			font-size:24rpx;
			
		}	
		.renwu-footer{
			display:flex;
			justify-content: flex-end;
			align-items: center;
			.btn-renwu-a{
				border-radius:100rpx;
				padding:10rpx 20rpx;
				background: #dd0000;
				border:2rpx solid #dd0000;
				color:#fff;
				font-size:24rpx;
			}
			.btn-renwu-b{
					border-radius:100rpx;
					padding:10rpx 20rpx;
					background: #fff;
					border:2rpx solid #dd0000;
					color:#dd00000;
					margin-right: 20rpx;
					font-size:24rpx;
			}
		}
	}
</style>
